/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.google.code.peersim.pastry.protocol;

/**
 * This interface must be implemented by those classes interested in receiving
 * notification of join-events from {@link PastryProtocol} instances.
 *
 * @author frusso
 * @version 0.1
 * @since 0.1
 */
public interface PastryJoinLsnrIfc {

  /**
   * Notifies the accomplishment of a join operation.
   *
   * @param info Information about the join operation
   */
  public void joined(JoinedInfo info);

  /**
   * Immutable description of the join operation.
   *
   * @author frusso
   * @since 0.1
   * @version 0.1
   */
  public static class JoinedInfo {

    private final int hops;
    private final PastryId nodeId;

    /**
     * Constructor.
     *
     * @param hops The number of hops
     * @param nodeId The id of the joined node
     */
    public JoinedInfo(int hops, PastryId nodeId) {
      this.hops = hops;
      this.nodeId = nodeId;
    }

    /**
     * Returns the number of hops.
     *
     * @return The number of hops
     */
    public int getHops() {
      return hops;
    }

    /**
     * Returns the id of the joined node.
     *
     * @return The id of the joined node
     */
    public PastryId getNodeId() {
      return nodeId;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
      return "JOINED_EVENT node: "+nodeId+" hops: "+hops;
    }
  }
}